<template>
      <div class="avatar" @click="onRegister">
        <el-popover
            :width="250"
            popper-style="box-shadow: rgb(14 18 22 / 35%) 0px 10px 38px -10px, rgb(14 18 22 / 20%) 0px 10px 20px -15px; padding: 20px;">
          <template #reference>
            <el-avatar :size="50" :src='circleUrl' @error="errorHandler">

            </el-avatar>
          </template>
          <template #default>
            <div class="currInfo">
              <div class="infoItem" @click="console.log(store.state.user)">
                  <div class="infoIcon">
                    <el-icon color="#475669"><Tickets /></el-icon>
                    <span>我的订单</span>
                  </div>
                  <div style="margin-right: 10px; display: flex; align-items: center">
                    <el-icon color="#475669"><ArrowRightBold /></el-icon>
                  </div>
                </div>
              <div class="infoItem" @click="userInfo">
                <div class="infoIcon">
                  <el-icon color="#475669"><Postcard /></el-icon>
                  <span>个人信息</span>
                </div>
                <div style="margin-right: 10px; display: flex; align-items: center">
                  <el-icon color="#475669"><ArrowRightBold /></el-icon>
                </div>
              </div>
              <div class="infoItem">
                <div class="infoIcon">
                  <el-icon color="#475669"><MoreFilled /></el-icon>
                  <span>更多</span>
                </div>
                <div style="margin-right: 10px; display: flex; align-items: center">
                  <el-icon color="#475669"><ArrowRightBold /></el-icon>
                </div>
              </div>
            </div>
          </template>
        </el-popover>
        <div class="user_massage">
          <strong :title="login.name">{{ login.name === "" ? "请登录" : login.name }}</strong>
          <span v-if="login.uid !== 0" :title="login.uid">uid: {{ login.uid }} </span>
        </div>
      </div>


</template>

<script setup>
import {ArrowRightBold, MoreFilled, Postcard, Tickets} from '@element-plus/icons-vue'
import {reactive, onMounted, ref} from "vue";
import {useRouter} from "vue-router";
import {useStore} from "vuex";
import axios from "axios";
import constant from "../../constant";


const errorHandler = () => true
const router = useRouter()
const store = useStore()

let register = reactive({
  name: '',
  password: ''
})

const baseUrl = store.state.baseUrl

let login = ref(
    {...store.state.user}
)

let circleUrl = login.value.image === '' ? baseUrl + '/image/avate.png' : baseUrl + login.value.image


function onRegister() {
  router.push('/login')
}

// 点击个人信息
function userInfo() {
  if (login.value.uid === 0) {
    onRegister()
  } else {
    router.push('/info')
  }
}

onMounted(() => {

  login.value = {...store.state.user}
})






</script>

<style scoped>
.avatar{
  width: 140px;
  display: flex;
  align-items: center;
  position: relative;
  left: 130px;
  cursor: pointer;
  /*justify-content: space-between;*/
}
.avatar strong{
  cursor: pointer;
  text-align: left;
}

.avatar strong:hover {
  color: #FFFFFF;
}

.infoItem {
  width: 100%;
  height: 30px;
  border-radius: 12px;
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.infoIcon {
  display: flex;
  align-items: center;
  margin-left: 10px;
  color: #475669;
}
.infoIcon span {
  margin-left: 10px;
}
.infoItem:hover {
  background-color:  #c6e2ff;
  color: #FFFFFF;
}
.form {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}

.item {
  display: flex;
  justify-content: center;
}
.inputCurr {
  width: 250px;
}
.curr {
  margin-left: 10px;
}
.buttonCurr {
  width: 100px;
}

.buttonCurr:hover {
  background-color: #79bbff;
  color: #FFFFFF;
}
.user_massage {
  display: flex;
  flex-direction: column;
  margin-left: 10px;
}
.user_massage span {
  width: 80px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow:ellipsis;
}
</style>